package com.dmtt.config;

import com.alibaba.fastjson.JSONObject;
import com.dmtt.util.R;
import com.dmtt.web.entity.AgvInfo;
import com.dmtt.web.service.CarManagerService;
import com.dmtt.web.socket.WebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.List;

@Configuration
@Component
@EnableScheduling
public class QuartzMq {

    @Autowired
    private RabbitMqService orderService;

    @Autowired
    private CarManagerService carManagerService;

    @Scheduled(fixedRate = 10000)
    @Async
    public void asd(){
        try {
            //报警
            orderService.makeOrder();
            //预警
            orderService.makeOrder1();
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    @Scheduled(fixedRate = 1000)
    @Async
    public void sendInfo(){
        try {
            R r = carManagerService.queryCar();
            WebSocketServer.sendInfo(JSONObject.toJSONString(r),"1");
        }catch (IOException e){
            e.printStackTrace();
        }
    }
    @Scheduled(fixedRate = 1000)
    @Async
    public void sendInfo1(){
        try {
            R r = carManagerService.querySlamCar();
            WebSocketServer.sendInfo(JSONObject.toJSONString(r),"2");
        }catch (IOException e){
            e.printStackTrace();
        }
    }


}
